ExternalProject_Add(sleef
    DEPENDS
        llvm-libcxx
    GIT_REPOSITORY https://github.com/shibatch/sleef.git
    SOURCE_DIR ${SOURCE_LOCATION}
    GIT_CLONE_FLAGS "--filter=tree:0"
    GIT_PROGRESS TRUE
    GIT_RESET c73b89fd6661230586196ba0ce29f7444cc5a2e8
    UPDATE_COMMAND ""
    CONFIGURE_ENVIRONMENT_MODIFICATION
        _IS_CONFIGURE=set:1
    CONFIGURE_COMMAND ${EXEC_HOST} ${CMAKE_COMMAND} -H<SOURCE_DIR> -B<BINARY_DIR>/host
        -GNinja
        -DCMAKE_BUILD_TYPE=Release
        -DBUILD_SHARED_LIBS=OFF
        -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
        -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
        -DCMAKE_C_COMPILER_WORKS=1
        -DCMAKE_CXX_COMPILER_WORKS=1
        -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
        -DSLEEF_BUILD_DFT=ON
        -DSLEEF_BUILD_QUAD=OFF
        -DSLEEF_DISABLE_OPENMP=ON
        -DSLEEF_ENABLE_LTO=OFF
        -DSLEEF_BUILD_TESTS=OFF
        -DSLEEF_DISABLE_SSE2=ON
        -DSLEEF_DISABLE_SSE4=ON
        -DSLEEF_DISABLE_FMA4=ON
        -DSLEEF_DISABLE_SVE=ON
        -DSLEEF_DISABLE_AVX=ON
        -DSLEEF_DISABLE_FFTW=ON
        -DSLEEF_DISABLE_MPFR=ON
        -DSLEEF_DISABLE_SSL=ON
        -DSLEEF_ENABLE_TESTER=OFF
        -DSLEEF_ENABLE_TLFLOAT=OFF
        -DOPENSSL_FOUND=OFF
        -DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=ON
        -DLIB_MPFR=''
        -DLIBFFTW3=''
        -DLIBGMP=''
        "-DCMAKE_C_FLAGS='-g0'"
        "-DCMALE_CXX_FLAGS='-g0'"
    COMMAND ${EXEC} ninja -C <BINARY_DIR>/host mkunroll mkrename mkdisp mkalias mkdisp mkdispatch mkrename_gnuabi mkmasked_gnuabi
    COMMAND ${EXEC} ${CMAKE_COMMAND} -H<SOURCE_DIR> -B<BINARY_DIR>
        ${cmake_conf_args}
        -DNATIVE_BUILD_DIR=<BINARY_DIR>/host
        -DSLEEF_SHOW_CONFIG=ON
        -DSLEEF_BUILD_INLINE_HEADERS=OFF
        -DSLEEF_DISABLE_OPENMP=ON
        -DSLEEF_BUILD_DFT=ON
        -DSLEEF_BUILD_QUAD=OFF
        -DSLEEF_ENABLE_CXX=ON
        -DSLEEF_BUILD_LIBM=ON
        -DSLEEF_ENABLE_LLVM_BITCODE=OFF
        -DSLEEF_ENABLE_LTO=OFF
        -DSLEEF_BUILD_TESTS=OFF
        -DSLEEF_DISABLE_SSE2=OFF
        -DSLEEF_DISABLE_SSE4=OFF
        -DSLEEF_DISABLE_LONG_DOUBLE=ON
        -DSLEEF_DISABLE_FMA4=ON
        -DSLEEF_DISABLE_FFTW=ON
        -DSLEEF_DISABLE_MPFR=ON
        -DSLEEF_DISABLE_SSL=ON
        -DSLEEF_ENABLE_TESTER=OFF
        -DSLEEF_ENABLE_TLFLOAT=OFF
        -DENABLE_GNUABI=ON
        -DOPENSSL_FOUND=OFF
        -DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=ON
        -DLIB_MPFR=''
        -DLIBFFTW3=''
        -DLIBGMP=''
    BUILD_ENVIRONMENT_MODIFICATION
        _PACKAGE_NAME=set:${package}
        _BINARY_DIR=set:<BINARY_DIR>
        _IS_UNWIND_ALLOWED=set:1
        _FORCE_HIDE_DLLEXPORT=set:1
    BUILD_COMMAND ${EXEC} ninja -C <BINARY_DIR> libsleef.a libsleefdft.a
          COMMAND ${EXEC} _LTO_ENABLED=0 _PGO_ENABLED=0 ninja -C <BINARY_DIR> libsleefgnuabi.a
    INSTALL_COMMAND ${EXEC} ${CMAKE_COMMAND} --install <BINARY_DIR>
            COMMAND ${EXEC} "echo 'Cflags: -DSLEEF_STATIC_LIBS -DIMPORT_IS_EXPORT -DSLEEF_ALWAYS_INLINE' >> ${MINGW_INSTALL_PREFIX}/lib/pkgconfig/sleef.pc"
            COMMAND ${EXEC} "echo 'Libs: -lsleef -lsleefdft' >> ${MINGW_INSTALL_PREFIX}/lib/pkgconfig/sleef.pc"
            COMMAND ${EXEC} cp ${MINGW_INSTALL_PREFIX}/lib/pkgconfig/sleef.pc ${MINGW_INSTALL_PREFIX}/lib/pkgconfig/sleefdft.pc
    LOG_DOWNLOAD 1 LOG_UPDATE 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1
)

force_rebuild_git(sleef)
cleanup(sleef install)
